import com.ktjy.entity.StorageRecord;
import com.ktjy.entity.Supplier;
import com.ktjy.entity.SysUser;
import com.ktjy.service.StorageRecordService;
import com.ktjy.service.SupplierService;
import com.ktjy.service.SysUserService;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

public class Main {
    Logger logger = LoggerFactory.getLogger(Main.class);

    @Test
    public void test1() { //sz2
        ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
        SupplierService supplierService = (SupplierService) context.getBean("supplierService");
        String supName = "清新";
        List<Supplier> supplierList = supplierService.getSupplierList(supName);
        for (Supplier supplier : supplierList) {
            logger.info("supplier:{}", supplier);
        }
    }
    //sz4
    @Test
    public void test2() {
        ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
        SysUserService sysUserService = (SysUserService) context.getBean("sysUserService");
        SysUser sysUser = new SysUser();
        sysUser.setAccount("qq");
        sysUser.setRealName("qq");
        sysUser.setPassword("123456");
        sysUser.setSex(1);
        sysUser.setBirthday(new Date());
        sysUser.setPhone("10020203030");
        sysUser.setAddress("qq");
        sysUser.setRoleId(3L);
        sysUser.setCreatedUserId(1L);
        sysUser.setCreatedTime(new Date());
        sysUser.setUpdatedUserId(null);
        sysUser.setUpdatedTime(null);

        int count=sysUserService.insert(sysUser);
        logger.info("count:{}",count);
    }
    @Test
    public void test3() {
        ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
        SysUserService sysUserService = (SysUserService) context.getBean("sysUserService");
        SysUser sysUser = new SysUser();
        sysUser.setId(16L);
        sysUser.setAccount("qq-修改");
        sysUser.setRealName("qq-修改");
        sysUser.setPassword("123456");
        sysUser.setSex(1);
        sysUser.setBirthday(new Date());
        sysUser.setPhone("10020203030");
        sysUser.setAddress("qq");
        sysUser.setRoleId(3L);
        sysUser.setCreatedUserId(1L);
        sysUser.setCreatedTime(new Date());
        sysUser.setUpdatedUserId(null);
        sysUser.setUpdatedTime(null);

        int count=sysUserService.update(sysUser);
        logger.info("count:{}",count);
    }
    @Test
    public void test4() {
        ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
        SysUserService sysUserService = (SysUserService) context.getBean("sysUserService");
        int id=16;
        int count=sysUserService.delete(id);
        logger.info("count:{}",count);
    }
    //    sz5
    @Test
    public void updateZhujie() throws ParseException {
        ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
        SupplierService supplierService = (SupplierService) context.getBean("supplierService");
        Supplier supplier = new Supplier();
        supplier.setId(116);
        supplier.setSupCode("S012");
        supplier.setSupName("疾简介-修改");
        supplier.setSupDesc("斤斤计较");
        supplier.setSupContact("熊静");
        supplier.setSupPhone("10020003000");
        supplier.setSupAddress("湖南郴州");
        supplier.setSupFax("0375-888888899");
        Date date = new SimpleDateFormat("yyyy-MM-dd").parse("2020-3-3");
        supplier.setCreatedTime(date);
        supplier.setUpdatedTime(new Date());
        supplier.setUpdatedUserId(2);

        int count = supplierService.updateSupplierZhujie(supplier);
        System.out.println("执行结果：" + count);
    }

    @Test
    public void deleteZhujie() throws ParseException {
        ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
        SupplierService supplierService = (SupplierService) context.getBean("supplierService");
        int id = 116;
        int count = supplierService.deleteSupplierZhujie(id);
        System.out.println("执行结果：" + count);
    }

//    sz6
    @Test
    public void test5() {
        ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
        StorageRecordService storageRecordService = (StorageRecordService) context.getBean("storageRecordService");
        StorageRecord storageRecord = new StorageRecord();
        storageRecord.setSrCode("S0020");
        storageRecord.setGoodsName("qqqq");
        storageRecord.setGoodsDesc("qqqqqqq");
        storageRecord.setGoodsUnit("eeeeeee");
        storageRecord.setGoodsCount(19);
        storageRecord.setTotalAmount(999);
        storageRecord.setPayStatus(1);
        storageRecord.setSupplierId(115);
        storageRecord.setCreatedUserId(1);
        storageRecord.setCreatedTime(new Date());
        storageRecord.setUpdatedUserId(2);
        storageRecord.setUpdatedTime(new Date());

        int count=storageRecordService.insertStorageRecord(storageRecord);
        logger.info("count:{}",count);
    }
    @Test
    public void test6() {
        ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
        StorageRecordService storageRecordService = (StorageRecordService) context.getBean("storageRecordService");
        StorageRecord storageRecord = new StorageRecord();
        storageRecord.setId(21);
        storageRecord.setSrCode("S0020");
        storageRecord.setGoodsName("qqqq-ss");
        storageRecord.setGoodsDesc("qqqqqqq-ss");
        storageRecord.setGoodsUnit("eeeeeee-ss");
        storageRecord.setGoodsCount(19);
        storageRecord.setTotalAmount(999);
        storageRecord.setPayStatus(1);
        storageRecord.setSupplierId(115);
        storageRecord.setCreatedUserId(1);
        storageRecord.setCreatedTime(new Date());
        storageRecord.setUpdatedUserId(2);
        storageRecord.setUpdatedTime(new Date());

        int count=storageRecordService.updateStorageRecord(storageRecord);
        logger.info("count:{}",count);
    }
    @Test
    public void test7() {
        ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
        StorageRecordService storageRecordService = (StorageRecordService) context.getBean("storageRecordService");
        int id=21;
        int count=storageRecordService.deleteStorageRecord(id);
        logger.info("count:{}",count);
    }
}
